// JavaScript Document
//-------------------------------------------
//fja koja omogucava editovanje mere
function changeEdit_Mere(id){
	
	obj_radio= document.getElementById("r_"+id);	
	
	//alert('edit:'+id+obj_radio.value);

	obj_j_id= document.getElementById("jed_id_"+id);

	
	obj_j_name= document.getElementById("jed_ime_"+id);

	
	obj_j_sname= document.getElementById("jed_ime_s_"+id);

	
	obj_save_button= document.getElementById("save_"+id);
	obj_delete_button= document.getElementById("delete_"+id);
	obj_edit_button= document.getElementById("edit_"+id);
	/*		
	obj_edit_button.innerHTML='<img src="gui/icons/cancel.gif" alt="" />';
	obj_edit_button.obj = tmpEditHldr;
	//obj_edit_button.xid = id;
	obj_edit_button.onclick = function(){
	this.obj.innerHTML = tmpBuffer[id];
	this.innerHTML = '<img src="gui/icons/edit.gif" alt="" />';
	*/
	if(obj_radio.value=="0"){
		jed_id_val= obj_radio.value;
		j_ime_val= obj_j_name.value;
		jed_ime_s_val= obj_j_sname.value;
		
		obj_radio.value="1";
		
		obj_j_name.disabled= false;
		obj_j_sname.disabled= false;
		
		//obj_save_button.style.visibility="visible";
		//obj_delete_button.style.visibility="visible";
		obj_save_button.style.display="block";
		obj_delete_button.style.display="block";
		
		obj_edit_button.innerHTML='<img src="gui/icons/cancel.gif" alt="" />';
			

		}
	else{	

		obj_radio.value="0";
		obj_j_name.disabled= true;
		obj_j_name.value= j_ime_val;		
		
		obj_j_sname.disabled= true;
		obj_j_sname.value= jed_ime_s_val;		
		
		obj_save_button.style.display="none";
		obj_delete_button.style.display="none";
			
		obj_edit_button.innerHTML='<img src="gui/icons/edit.gif" alt="" />';
		

	}
}
//-------------------------------------------
//izmeni vrednost polja (select lista) i prikaze delatnosti iz selektovanog polja (kategorija_id)
function changeVal_Mere(obj){
	broj = obj.options[obj.selectedIndex].value;
	LoadRSDoc('jedinice_mere.php?a=show&j='+broj,'setContent');
	//alert(listText);
}
//-------------------------------------------
//prikaz delatnosti po kategoriji id
//prikaz delatnosti za zadato id- kategorija ID
function show_Mere(id){
	//alert(id);
	LoadRSDoc('jedinice_mere.php?a=show&j='+id,'setContent');
}
//-------------------------------------------
//cuva izmene u polju
function saveChanges_Mere(id){
	//alert(id);
	obj_radio= document.getElementById("r_"+id);
	obj_id= document.getElementById("jed_id_"+id);
	obj_j_name= document.getElementById("jed_ime_"+id);
	obj_j_sname= document.getElementById("jed_ime_s_"+id);

	obj_save_button= document.getElementById("save_"+id);
	
	param='jedinice_mere.php?a=save&j='+obj_id.value+'&ime='+obj_j_name.value+'&ime_s='+obj_j_sname.value;
	//alert(param);
	if(confirm('Da li želite da izmenite polje: '+obj_j_name.value+' ?'))
		LoadRSDoc( param , 'refresh_Mere()');
}
//-------------------------------------------
//osvezava prikaz mera
function refresh_Mere(){
	param="";
	//alert(requestResponse);
	//return;
	//if(id){
	//	param+='&j='+id;
	//}
	
	LoadRSDoc('jedinice_mere.php?a=show'+param,'setContent');
}
//-------------------------------------------
//otvara stranu <strana> rezultata mera
function open_Mere( strana){
	param="";
	if(strana){
		param+='&s='+strana;
	}
	LoadRSDoc('jedinice_mere.php?a=show'+param,'setContent');
}
//--------------------------------------------
//omogucava unos nove mere
function new_Mere(){
	obj_new= document.getElementById("jed_new");
	obj_new.style.display = "block";
	obj_enter= document.getElementById("jed_ime_new");
	obj_enter.focus();
	obj_enter.select();
}

//--------------------------------------------
//dodaje novu meru
function add_Mere(){
	obj_j_name= document.getElementById("jed_ime_new");
	obj_j_sname= document.getElementById("jed_ime_s_new");
	
	param='jedinice_mere.php?a=add&ime='+obj_j_name.value+'&ime_s='+obj_j_sname.value;
	//alert(param);
	//if(confirm('Da li želite da unesete polje: '+obj_j_name.value+' ?')){
		LoadRSDoc(param,'refresh_Mere()');
		//LoadRSDoc(param,'setContent');
		LoadRSDoc('jedinice_mere.php?a=show','refresh_Mere()');
	//}
	//LoadRSDoc('jedinice_mere.php?a=show&j='+id,'refresh_Mere');
}

//-------------------------------------------
//brise meru ID
function del_Mere(id){
	obj_radio= document.getElementById("r_"+id);
	obj_j_name= document.getElementById("jed_ime_"+id);
	obj_j_id= document.getElementById("jed_id_"+id);

	obj_j_sname= document.getElementById("jed_ime_s_"+id);

	param='jedinice_mere.php?a=del&j='+obj_j_id.value+'&ime='+obj_j_name.value+'&ime_s='+obj_j_sname.value;
	//alert(param);
	//LoadRSDoc(param,'setContent');
	if(confirm('Da li želite da izbrišete polje: '+obj_j_name.value+' ?'))
		LoadRSDoc( param , 'refresh_Mere()');
}